   
    
    $(function() {
    	   var userInfo = $.cookie('login_cookie');
           if (userInfo != null && userInfo != "") {
   			var name = userInfo.split("%")[1];
   			$(".header-left").html(
   					"欢迎，"+name+"&nbsp;&nbsp;&nbsp;<a href='javascript:void(0)' class='link-logout' onclick='logout()'>[退出]</a>"		
   			);
   		} else {
   			window.location.href = ("login.html");
   		}
    	 $.ajax({
	          url:"teacher/list",
	          type: "GET",
	          success: function(data) {
			if(data!=null){
	            var student=data;
	            for (var i = 0; i < student.length; i++) {
	             $("#table_list").append(
	            		 "<tr><td>"
	            		
	            		 + student[i].id + "</td><td>"
	            		 + student[i].name + "</td><td>"
	            		 + student[i].gender + "</td><td>"
	            		 +student[i].phone +"</td><td>"
	            		 + student[i].age + "</td><td>"
	            		 +"<a href='update-teacher.html?"+student[i].id+"') style='cursor:pointer'><i class='fa  fa-pencil'>&nbsp;修改</i></a>&nbsp;&nbsp;&nbsp;&nbsp;" +
	            		 		"<a href='javascript:void(0)' onclick=deleteTea('"+student[i].id+"') style='cursor:pointer'><i class='fa fa-trash-o'>&nbsp;删除</i></a>"+ "</td></tr>"
	            		 
	            		 );
	        		}
				}
	          }
			});
    	//为注册按钮绑定点击注册时间  出发regist方法
    	$("#stu_search").click(function(){
    		
    		return serach();
    	});
    }) 
    function logout() {
		$.ajax({
			url : "user/logout",
			type : "post",
			dateType : "json",
			success : function(data) {
				window.location.reload();
			},
			error : function(e) {
				alert("请求失败！");
			}
		})
    }
function deleteTea(id){
	$.ajax({
		url:"teacher/delete?id="+id,
		type:"get",
		dataType:"json",
		async:false,
		success:function(data){
			var flag=data.success;
			if(flag){
				alert("删除成功！");
				window.location.href="select-teacher.html";
				
			}else{
				alert("删除失败！");
			}
		}
    })
    }
    
   

    
function serach(){
	var search=$("input[name='stu_search_text']").val();
	$('#table_list').children().empty();
	$.ajax({
		url:"teacher/search",
		data:{'Info':search},
		type:"post",
		dataType:"json",
		async:false,
		success:function(data){
			if(data!=null){
	            var student=data;
	            for (var i = 0; i < student.length; i++) {
	            	  $("#table_list").append(
	 	            		 "<tr><td>"
	 	            		
	 	            		 + student[i].id + "</td><td>"
	 	            		 + student[i].name + "</td><td>"
	 	            		 + student[i].gender + "</td><td>"
	 	            		 +student[i].phone +"</td><td>"
	 	            		 + student[i].age + "</td><td>"
	 	            		 +"<a href='update-teacher.html?"+student[i].id+"') style='cursor:pointer'><i class='fa  fa-pencil'>&nbsp;修改</i></a>&nbsp;&nbsp;&nbsp;&nbsp;" +
	 	            		 		"<a href='javascript:void(0)' onclick=deleteTea('"+student[i].id+"') style='cursor:pointer'><i class='fa fa-trash-o'>&nbsp;删除</i></a>"+ "</td></tr>"
	 	            		 
	 	            		 );
	        		}
				}
			}
	})
	}